package com.example.easyexcel.controller;

import com.alibaba.excel.EasyExcel;
import com.example.easyexcel.config.DemoDataListener;
import com.example.easyexcel.entity.BankInfo;
import com.example.easyexcel.service.iml.BankServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.awt.datatransfer.DataTransferer;
import java.io.File;
import java.util.List;

import static com.alibaba.excel.EasyExcel.*;

/**
 * ClassName:beginController
 * Package:com.example.easyexcel
 * Description:
 *
 * @date:2021/6/4 14:28
 * @author:xy
 */


@RestController
@RequestMapping("excel")
public class BeginController {
      @Autowired
      private BankServiceImpl bankService ;


    @PostMapping("/read")
     void readExcel(){
        read(new File("J:\\Xworkspace/demo.xlsx"), BankInfo.class,new DemoDataListener()).sheet().doRead();

    }
    @GetMapping("/write")
     void writeExcel(){
     //   read(new File("J:\\Xworkspace/demo.xlsx"), BankInfo.class,new DemoDataListener()).sheet().doRead();
        BankServiceImpl bankService = new BankServiceImpl();
        List<BankInfo> bankInfos = bankService.selectList();
         EasyExcel.write("J:\\Xworkspace/demo666.xlsx", BankInfo.class).sheet("银行").doWrite(bankInfos);

    }

}
